home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Shutdown FX 2.1 / source / sfx control app ƒ / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  5.2 KB  |  200 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "about.h"
  25. #include "prefs.h"
  26. #include "util.h"
  27.  
  28. /*-----------------------------------------------------------------------------------*/
  29. /* internal stuff for about.c                                                        */
  30.  
  31. static void SetupTheAboutBox(WindowDataHandle theData);
  32. static void InitializeTheAboutBox(WindowDataHandle theData);
  33. static void OpenTheAboutBox(WindowDataHandle theData);
  34. static void ResizeTheAboutBox(WindowDataHandle theData);
  35. static void ShutdownTheAboutBox(WindowDataHandle theData);
  36. static void DrawTheAboutBox(Boolean isColor);
  37. static void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  38. static void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  39.  
  40. Boolean            gUseAlternate;
  41.  
  42. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  43. {
  44.     short            theDepth;
  45.     
  46.     switch (theMessage)    /* see graphics.h for list of messages*/
  47.     {
  48.         case kKeydown:                            /* close about box on keypress */
  49.         case kMousedown:                        /* or mouseclick */
  50.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  51.             return kSuccess;
  52.             break;
  53.         case kUpdate:
  54.             theDepth=misc&0x7fff;                /* pixel depth */
  55.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  56.             return kSuccess;
  57.             break;
  58.         case kInitialize:
  59.             InitializeTheAboutBox(theData);
  60.             return kFailure;
  61.         case kOpen:
  62.             OpenTheAboutBox(theData);
  63.             return kSuccess;
  64.             break;
  65.         case kStartup:
  66.             SetupTheAboutBox(theData);
  67.             return kSuccess;
  68.             break;
  69.         case kShutdown:
  70.             ShutdownTheAboutBox(theData);
  71.             return kSuccess;
  72.             break;
  73.     }
  74.     
  75.     return kFailure;        /* for all other messages, defer to default processing */
  76. }
  77.  
  78. void SetupTheAboutBox(WindowDataHandle theData)
  79. {
  80.     unsigned char    *theTitle="\pShutdown FX";
  81.     
  82.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  83.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  84.     (**theData).hasCloseBox=TRUE;
  85.     (**theData).maxDepth=1;
  86.     gUseAlternate=FALSE;
  87. }
  88.  
  89. void InitializeTheAboutBox(WindowDataHandle theData)
  90. {
  91.     (**theData).windowWidth=170;
  92.     (**theData).windowHeight=158;
  93. }
  94.  
  95. void OpenTheAboutBox(WindowDataHandle theData)
  96. {
  97.     KeyMap            rawKeys;
  98.     unsigned short    theKeys[8];
  99.     
  100.     ShowWindow(GetWindowGrafPtr(theData));
  101.     SelectWindow(GetWindowGrafPtr(theData));
  102.     GetKeys(rawKeys);
  103.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  104.     if (theKeys[3]&4)    /* option key down? */
  105.     {
  106.         if (!gUseAlternate)
  107.         {
  108.             gUseAlternate=TRUE;
  109.             (**theData).offscreenNeedsUpdate=TRUE;
  110.         }
  111.     }
  112.     else
  113.     {
  114.         if (gUseAlternate)
  115.         {
  116.             gUseAlternate=FALSE;
  117.             (**theData).offscreenNeedsUpdate=TRUE;
  118.         }
  119.     }
  120.     if ((**theData).offscreenNeedsUpdate)
  121.         UpdateTheWindow(theData);
  122. }
  123.  
  124. void ShutdownTheAboutBox(WindowDataHandle theData)
  125. {
  126. }
  127.  
  128. void DrawTheAboutBox(Boolean isColor)
  129. {
  130.     RGBColor        oldForeColor, oldBackColor;
  131.     short            row;
  132.     Handle            textHandle;
  133.     Str255            theLine;
  134.     unsigned long    pos;
  135.     unsigned long    theSize;
  136.     GrafPtr            curPort;
  137.     short            theCenter;
  138.     RGBColor        myGray={49152, 49152, 49152};
  139.     
  140.     GetPort(&curPort);
  141.     if (isColor)
  142.     {
  143.         GetForeColor(&oldForeColor);
  144.         GetBackColor(&oldBackColor);
  145.         RGBForeColor(&myGray);
  146.         PaintRect(&(curPort->portRect));
  147.         RGBForeColor(&oldForeColor);
  148.         RGBBackColor(&oldBackColor);
  149.         TextMode(srcOr);
  150.     }
  151.     else
  152.     {
  153.         FillRect(&(curPort->portRect), black);
  154.         TextMode(srcXor);
  155.     }
  156.     
  157.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  158.     
  159.     TextFont(geneva);
  160.     TextSize(9);
  161.     row=16;
  162.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  163.     if (textHandle==0L)
  164.         return;
  165.     if (*textHandle==0L)
  166.         LoadResource(textHandle);
  167.     if (*textHandle==0L)
  168.         return;
  169.     pos=0L;
  170.     theSize=SizeResource(textHandle);
  171.     do
  172.     {
  173.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  174.         DrawTheAboutString(theLine, &row, theCenter);
  175.     }
  176.     while (pos<theSize);
  177.     ReleaseResource(textHandle);
  178.     if (isColor)
  179.         ForeColor(blackColor);
  180.     TextMode(srcCopy);
  181.     TextSize(12);
  182.     TextFont(0);
  183. }
  184.  
  185. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  186. {
  187.     unsigned char    theChar;
  188.     
  189.     theLine[0]=0x00;
  190.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  191.         theLine[++theLine[0]]=theChar;
  192. }
  193.  
  194. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  195. {
  196.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  197.     DrawString(theString);
  198.     *theRow+=12;
  199. }
  200.